package org.moonlight.jvm.instructions.math.bitoperate.shift;

import org.moonlight.jvm.instructions.base.NoOperandsInstruction;
import org.moonlight.jvm.rtda.exclusive.Frame;
import org.moonlight.jvm.rtda.exclusive.OperandStack;

/**
 * ISHL: 从 操作数栈 中弹出两个 int变量，进行 左移运算，然后把结果推入操作数栈。
 *
 * https://blog.csdn.net/qq_46351133/article/details/116901004?spm=1001.2014.3001.5502
 * https://weread.qq.com/web/reader/88232cb05c99098821c4ba0k93d32d9025693db85ed9e60
 * https://github.com/zxh0/jvmgo-book/blob/master/v1/code/go/src/jvmgo/ch05/instructions/math/sh.go
 *
 * @author Moonlight
 * @createTime 2023/8/17 9:04
 **/
public class IShl extends NoOperandsInstruction {

    @Override
    public void execute(Frame frame) {
        OperandStack operandStack = frame.getOperandStack();

        int a = operandStack.popInt();
        int b = operandStack.popInt();
        int s = a & 0x1f;

        operandStack.pushInt( b << s );
    }

}
